package com.atguigu.springcloud.service.impl;


import com.atguigu.springcloud.service.IMessageProvider;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cloud.stream.annotation.EnableBinding;
import org.springframework.cloud.stream.messaging.Source;
import org.springframework.messaging.MessageChannel;
import org.springframework.messaging.support.MessageBuilder;
import org.springframework.stereotype.Service;

import java.util.UUID;


@EnableBinding(Source.class)       //定义消息的推送管道
public class MessageProviderImpl implements IMessageProvider {

    private final Logger log = LoggerFactory.getLogger(MessageProviderImpl.class);

    @Autowired
    private MessageChannel output;


    @Override
    public String send() {
        String message = UUID.randomUUID().toString().replace("-", "");
        output.send(MessageBuilder.withPayload(message).build());
        log.info("=====「发送消息」:{}成功！=====",message);
        return null;
    }
}
